
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/02/2012 09:57:48
-- Generated from EDMX file: E:\artur\roboczy_domowe\aplikacje\Przedszkole\PrzedszkoleZywienie\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Zywienie];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Dni_TypyPosilkow]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Dni] DROP CONSTRAINT [FK_Dni_TypyPosilkow];
GO
IF OBJECT_ID(N'[dbo].[FK_DniPotrawy_Potrawy]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DniPotrawy] DROP CONSTRAINT [FK_DniPotrawy_Potrawy];
GO
IF OBJECT_ID(N'[dbo].[FK_DniPotrawy_TypyPosilkow]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DniPotrawy] DROP CONSTRAINT [FK_DniPotrawy_TypyPosilkow];
GO
IF OBJECT_ID(N'[dbo].[FK_DniProdukty_Produkty]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DniProdukty] DROP CONSTRAINT [FK_DniProdukty_Produkty];
GO
IF OBJECT_ID(N'[dbo].[FK_Faktury_Firmy]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Faktury] DROP CONSTRAINT [FK_Faktury_Firmy];
GO
IF OBJECT_ID(N'[dbo].[FK_Przychody_Faktury]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Przychody] DROP CONSTRAINT [FK_Przychody_Faktury];
GO
IF OBJECT_ID(N'[dbo].[FK_Przychody_Produkty]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Przychody] DROP CONSTRAINT [FK_Przychody_Produkty];
GO
IF OBJECT_ID(N'[dbo].[FK_Przychody_Wz]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Przychody] DROP CONSTRAINT [FK_Przychody_Wz];
GO
IF OBJECT_ID(N'[dbo].[FK_Rozchody_Produkty]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rozchody] DROP CONSTRAINT [FK_Rozchody_Produkty];
GO
IF OBJECT_ID(N'[dbo].[FK_Wz_Faktury]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Wz] DROP CONSTRAINT [FK_Wz_Faktury];
GO
IF OBJECT_ID(N'[dbo].[FK_Wz_Firmy]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Wz] DROP CONSTRAINT [FK_Wz_Firmy];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Dni]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Dni];
GO
IF OBJECT_ID(N'[dbo].[DniPotrawy]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DniPotrawy];
GO
IF OBJECT_ID(N'[dbo].[DniProdukty]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DniProdukty];
GO
IF OBJECT_ID(N'[dbo].[Faktury]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Faktury];
GO
IF OBJECT_ID(N'[dbo].[Firmy]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Firmy];
GO
IF OBJECT_ID(N'[dbo].[Jadlospis]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Jadlospis];
GO
IF OBJECT_ID(N'[dbo].[Potrawy]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Potrawy];
GO
IF OBJECT_ID(N'[dbo].[Produkty]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Produkty];
GO
IF OBJECT_ID(N'[dbo].[Przychody]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Przychody];
GO
IF OBJECT_ID(N'[dbo].[Rozchody]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rozchody];
GO
IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO
IF OBJECT_ID(N'[dbo].[TypyPosilkow]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TypyPosilkow];
GO
IF OBJECT_ID(N'[dbo].[Wz]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Wz];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Dni'
CREATE TABLE [dbo].[Dni] (
    [IdDnia] int IDENTITY(1,1) NOT NULL,
    [Data] datetime  NOT NULL,
    [IdPosilku] varchar(50)  NOT NULL,
    [IloscDzieci] int  NULL,
    [IloscPersonelu] int  NULL
);
GO

-- Creating table 'DniPotrawy'
CREATE TABLE [dbo].[DniPotrawy] (
    [IdDniPotrawy] int IDENTITY(1,1) NOT NULL,
    [Data] datetime  NOT NULL,
    [IdPosilku] varchar(50)  NOT NULL,
    [IdPotrawy] int  NOT NULL
);
GO

-- Creating table 'DniProdukty'
CREATE TABLE [dbo].[DniProdukty] (
    [IdDniProdukty] int IDENTITY(1,1) NOT NULL,
    [Data] datetime  NOT NULL,
    [IdProduktu] int  NOT NULL,
    [CenaBrutto] decimal(18,0)  NOT NULL,
    [Ilosc] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'Faktury'
CREATE TABLE [dbo].[Faktury] (
    [IdFaktury] int IDENTITY(1,1) NOT NULL,
    [Nr] nvarchar(max)  NULL,
    [DataWystawienia] datetime  NULL,
    [DataPlatnosci] datetime  NULL,
    [KwotaNetto] decimal(18,0)  NULL,
    [KwotaBrutto] decimal(18,0)  NULL,
    [Vat] decimal(18,0)  NULL,
    [StawkaVat] decimal(18,0)  NULL,
    [Opis] nvarchar(max)  NULL,
    [IdFirmy] int  NULL
);
GO

-- Creating table 'Firmy'
CREATE TABLE [dbo].[Firmy] (
    [IdFirmy] int IDENTITY(1,1) NOT NULL,
    [Nazwa] nvarchar(50)  NULL,
    [Regon] nvarchar(50)  NULL,
    [Adres] nvarchar(max)  NULL,
    [Telefon] nvarchar(50)  NULL,
    [Uwagi] nvarchar(max)  NULL,
    [Nip] nvarchar(max)  NULL
);
GO

-- Creating table 'Jadlospis'
CREATE TABLE [dbo].[Jadlospis] (
    [IdJadlospisu] int IDENTITY(1,1) NOT NULL,
    [DataPoczatkowa] datetime  NOT NULL,
    [DataKoncowa] datetime  NOT NULL,
    [Opis] nvarchar(max)  NULL
);
GO

-- Creating table 'Potrawy'
CREATE TABLE [dbo].[Potrawy] (
    [IdPotrawy] int IDENTITY(1,1) NOT NULL,
    [NazwaPotrawy] nvarchar(max)  NOT NULL,
    [Lekka] smallint  NULL,
    [GrupaPotraw] nvarchar(max)  NULL
);
GO

-- Creating table 'Produkty'
CREATE TABLE [dbo].[Produkty] (
    [IdProduktu] int IDENTITY(1,1) NOT NULL,
    [Nazwa] nvarchar(255)  NOT NULL,
    [Jednostka] nvarchar(50)  NOT NULL,
    [Opis] nvarchar(max)  NULL,
    [GrupyProduktow] nvarchar(255)  NULL
);
GO

-- Creating table 'Przychody'
CREATE TABLE [dbo].[Przychody] (
    [IdPrzychodu] int IDENTITY(1,1) NOT NULL,
    [IdProduktu] int  NOT NULL,
    [Data] datetime  NOT NULL,
    [Opis] nvarchar(max)  NULL,
    [CenaBrutto] decimal(18,0)  NOT NULL,
    [CenaNetto] decimal(18,0)  NULL,
    [Vat] decimal(18,0)  NULL,
    [StawkaVat] decimal(18,0)  NOT NULL,
    [Ilosc] decimal(18,0)  NOT NULL,
    [IdWz] int  NULL,
    [IdFaktury] int  NULL
);
GO

-- Creating table 'Rozchody'
CREATE TABLE [dbo].[Rozchody] (
    [idRozchodu] int IDENTITY(1,1) NOT NULL,
    [IdProduktu] int  NOT NULL,
    [Data] datetime  NOT NULL,
    [Opis] nvarchar(max)  NULL,
    [CenaBrutto] decimal(18,0)  NOT NULL,
    [Ilosc] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'sysdiagrams'
CREATE TABLE [dbo].[sysdiagrams] (
    [name] nvarchar(128)  NOT NULL,
    [principal_id] int  NOT NULL,
    [diagram_id] int IDENTITY(1,1) NOT NULL,
    [version] int  NULL,
    [definition] varbinary(max)  NULL
);
GO

-- Creating table 'TypyPosilkow'
CREATE TABLE [dbo].[TypyPosilkow] (
    [IdTypuPosilku] varchar(50)  NOT NULL,
    [Nazwa] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Wz'
CREATE TABLE [dbo].[Wz] (
    [IdWz] int IDENTITY(1,1) NOT NULL,
    [Opis] nvarchar(max)  NULL,
    [Nr] nvarchar(max)  NULL,
    [IdFaktury] int  NULL,
    [IdFirmy] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [IdDnia] in table 'Dni'
ALTER TABLE [dbo].[Dni]
ADD CONSTRAINT [PK_Dni]
    PRIMARY KEY CLUSTERED ([IdDnia] ASC);
GO

-- Creating primary key on [IdDniPotrawy] in table 'DniPotrawy'
ALTER TABLE [dbo].[DniPotrawy]
ADD CONSTRAINT [PK_DniPotrawy]
    PRIMARY KEY CLUSTERED ([IdDniPotrawy] ASC);
GO

-- Creating primary key on [IdDniProdukty] in table 'DniProdukty'
ALTER TABLE [dbo].[DniProdukty]
ADD CONSTRAINT [PK_DniProdukty]
    PRIMARY KEY CLUSTERED ([IdDniProdukty] ASC);
GO

-- Creating primary key on [IdFaktury] in table 'Faktury'
ALTER TABLE [dbo].[Faktury]
ADD CONSTRAINT [PK_Faktury]
    PRIMARY KEY CLUSTERED ([IdFaktury] ASC);
GO

-- Creating primary key on [IdFirmy] in table 'Firmy'
ALTER TABLE [dbo].[Firmy]
ADD CONSTRAINT [PK_Firmy]
    PRIMARY KEY CLUSTERED ([IdFirmy] ASC);
GO

-- Creating primary key on [IdJadlospisu] in table 'Jadlospis'
ALTER TABLE [dbo].[Jadlospis]
ADD CONSTRAINT [PK_Jadlospis]
    PRIMARY KEY CLUSTERED ([IdJadlospisu] ASC);
GO

-- Creating primary key on [IdPotrawy] in table 'Potrawy'
ALTER TABLE [dbo].[Potrawy]
ADD CONSTRAINT [PK_Potrawy]
    PRIMARY KEY CLUSTERED ([IdPotrawy] ASC);
GO

-- Creating primary key on [IdProduktu] in table 'Produkty'
ALTER TABLE [dbo].[Produkty]
ADD CONSTRAINT [PK_Produkty]
    PRIMARY KEY CLUSTERED ([IdProduktu] ASC);
GO

-- Creating primary key on [IdPrzychodu] in table 'Przychody'
ALTER TABLE [dbo].[Przychody]
ADD CONSTRAINT [PK_Przychody]
    PRIMARY KEY CLUSTERED ([IdPrzychodu] ASC);
GO

-- Creating primary key on [idRozchodu] in table 'Rozchody'
ALTER TABLE [dbo].[Rozchody]
ADD CONSTRAINT [PK_Rozchody]
    PRIMARY KEY CLUSTERED ([idRozchodu] ASC);
GO

-- Creating primary key on [diagram_id] in table 'sysdiagrams'
ALTER TABLE [dbo].[sysdiagrams]
ADD CONSTRAINT [PK_sysdiagrams]
    PRIMARY KEY CLUSTERED ([diagram_id] ASC);
GO

-- Creating primary key on [IdTypuPosilku] in table 'TypyPosilkow'
ALTER TABLE [dbo].[TypyPosilkow]
ADD CONSTRAINT [PK_TypyPosilkow]
    PRIMARY KEY CLUSTERED ([IdTypuPosilku] ASC);
GO

-- Creating primary key on [IdWz] in table 'Wz'
ALTER TABLE [dbo].[Wz]
ADD CONSTRAINT [PK_Wz]
    PRIMARY KEY CLUSTERED ([IdWz] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [IdPosilku] in table 'Dni'
ALTER TABLE [dbo].[Dni]
ADD CONSTRAINT [FK_Dni_TypyPosilkow]
    FOREIGN KEY ([IdPosilku])
    REFERENCES [dbo].[TypyPosilkow]
        ([IdTypuPosilku])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Dni_TypyPosilkow'
CREATE INDEX [IX_FK_Dni_TypyPosilkow]
ON [dbo].[Dni]
    ([IdPosilku]);
GO

-- Creating foreign key on [IdPotrawy] in table 'DniPotrawy'
ALTER TABLE [dbo].[DniPotrawy]
ADD CONSTRAINT [FK_DniPotrawy_Potrawy]
    FOREIGN KEY ([IdPotrawy])
    REFERENCES [dbo].[Potrawy]
        ([IdPotrawy])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DniPotrawy_Potrawy'
CREATE INDEX [IX_FK_DniPotrawy_Potrawy]
ON [dbo].[DniPotrawy]
    ([IdPotrawy]);
GO

-- Creating foreign key on [IdPosilku] in table 'DniPotrawy'
ALTER TABLE [dbo].[DniPotrawy]
ADD CONSTRAINT [FK_DniPotrawy_TypyPosilkow]
    FOREIGN KEY ([IdPosilku])
    REFERENCES [dbo].[TypyPosilkow]
        ([IdTypuPosilku])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DniPotrawy_TypyPosilkow'
CREATE INDEX [IX_FK_DniPotrawy_TypyPosilkow]
ON [dbo].[DniPotrawy]
    ([IdPosilku]);
GO

-- Creating foreign key on [IdProduktu] in table 'DniProdukty'
ALTER TABLE [dbo].[DniProdukty]
ADD CONSTRAINT [FK_DniProdukty_Produkty]
    FOREIGN KEY ([IdProduktu])
    REFERENCES [dbo].[Produkty]
        ([IdProduktu])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DniProdukty_Produkty'
CREATE INDEX [IX_FK_DniProdukty_Produkty]
ON [dbo].[DniProdukty]
    ([IdProduktu]);
GO

-- Creating foreign key on [IdFirmy] in table 'Faktury'
ALTER TABLE [dbo].[Faktury]
ADD CONSTRAINT [FK_Faktury_Firmy]
    FOREIGN KEY ([IdFirmy])
    REFERENCES [dbo].[Firmy]
        ([IdFirmy])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Faktury_Firmy'
CREATE INDEX [IX_FK_Faktury_Firmy]
ON [dbo].[Faktury]
    ([IdFirmy]);
GO

-- Creating foreign key on [IdFaktury] in table 'Przychody'
ALTER TABLE [dbo].[Przychody]
ADD CONSTRAINT [FK_Przychody_Faktury]
    FOREIGN KEY ([IdFaktury])
    REFERENCES [dbo].[Faktury]
        ([IdFaktury])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Przychody_Faktury'
CREATE INDEX [IX_FK_Przychody_Faktury]
ON [dbo].[Przychody]
    ([IdFaktury]);
GO

-- Creating foreign key on [IdFaktury] in table 'Wz'
ALTER TABLE [dbo].[Wz]
ADD CONSTRAINT [FK_Wz_Faktury]
    FOREIGN KEY ([IdFaktury])
    REFERENCES [dbo].[Faktury]
        ([IdFaktury])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Wz_Faktury'
CREATE INDEX [IX_FK_Wz_Faktury]
ON [dbo].[Wz]
    ([IdFaktury]);
GO

-- Creating foreign key on [IdFirmy] in table 'Wz'
ALTER TABLE [dbo].[Wz]
ADD CONSTRAINT [FK_Wz_Firmy]
    FOREIGN KEY ([IdFirmy])
    REFERENCES [dbo].[Firmy]
        ([IdFirmy])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Wz_Firmy'
CREATE INDEX [IX_FK_Wz_Firmy]
ON [dbo].[Wz]
    ([IdFirmy]);
GO

-- Creating foreign key on [IdProduktu] in table 'Przychody'
ALTER TABLE [dbo].[Przychody]
ADD CONSTRAINT [FK_Przychody_Produkty]
    FOREIGN KEY ([IdProduktu])
    REFERENCES [dbo].[Produkty]
        ([IdProduktu])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Przychody_Produkty'
CREATE INDEX [IX_FK_Przychody_Produkty]
ON [dbo].[Przychody]
    ([IdProduktu]);
GO

-- Creating foreign key on [IdProduktu] in table 'Rozchody'
ALTER TABLE [dbo].[Rozchody]
ADD CONSTRAINT [FK_Rozchody_Produkty]
    FOREIGN KEY ([IdProduktu])
    REFERENCES [dbo].[Produkty]
        ([IdProduktu])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rozchody_Produkty'
CREATE INDEX [IX_FK_Rozchody_Produkty]
ON [dbo].[Rozchody]
    ([IdProduktu]);
GO

-- Creating foreign key on [IdWz] in table 'Przychody'
ALTER TABLE [dbo].[Przychody]
ADD CONSTRAINT [FK_Przychody_Wz]
    FOREIGN KEY ([IdWz])
    REFERENCES [dbo].[Wz]
        ([IdWz])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Przychody_Wz'
CREATE INDEX [IX_FK_Przychody_Wz]
ON [dbo].[Przychody]
    ([IdWz]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------